<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>用户登录</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport" content="width=device-width,initial-scale=1"/>
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/login.css">
<script src="../js/jquery-1.12.4.js"></script>
<script src="js/bootstrap.min.js"></script>
<!--[if lt IE 9]>
	<script src="http://css3-mediaqueries-js.googlecode.com/svn/trunk/css3-mediaqueries.js"></script>
    <script src="http://cdn.bootcss.com/html5shiv/3.7.0/html5shiv.min.js"></script>
    <script src="http://cdn.bootcss.com/respond.js/1.3.0/respond.min.js"></script>
<![endif]-->
<script>


	$(function(){ 
		$(".container").css("position","fixed").css("top",($(window).height()-$(".container").height())/2)
		.css("left",($(window).width()-$(".container").width())/2);
		
		$('.close-button').click(function(){
			$(this).parent().removeClass("slidePageInFromLeft").addClass("slidePageBackLeft");
		});
		
		$(window).resize(function(){
			$(".container").css("position","fixed").css("top",($(window).height()-$(".container").height())/2)
			.css("left",($(window).width()-$(".container").width())/2);
		});
		
		$.post("../rolesServlet",{op:"findAllRoles"},function(data){
			
			var str="";
			var str1="";
			$.each(data,function(index,item){
				str+="<li><a id='"+item.rid+ "' href=\"javascript:login('"+item.rid+"','loginrole')\">"+item.rname+"</a></li>";
				str1+="<li><a id='"+item.rid+"' href=\"javascript:login('"+item.rid+"','role')\">"+item.rname+"</a></li>";

			});
			$("#registerRoles").html("").append($(str1));
			$("#loginRoles").html("").append($(str));
		},"json");
		//验证码框的颜色还原
		$("#vcode").focus(function(){
			$(this).css("border-color","#eee");
		});
		//重新输入密码的框的颜色还原
		$("#rpwds").css("border-color","#eee");
			
	});
	
	function login(id,role) {
    	var flag = $("#"+id).text();
    	$("#"+role).val(flag);
    	$("#rodeId").val(id);//把id存起来
	}
	
	function showRegisterPage(){
		$(".register-page").addClass("slidePageInFromLeft").removeClass("slidePageBackLeft");
	
	}
	
	function backlogin(){
		$(".register-page").removeClass("slidePageInFromLeft").addClass("slidePageBackLeft");
	}
	function adminLogin(){
		var role=$.trim($("#rodeId").val());
		var name=$.trim($("#uname").val());
		var pwd=$.trim($("#pwd").val());
		var code=$.trim($("#vcode").val());
		if(role==""){
			return;
		}
		if(name==""){
			return;
		}
		if(pwd==""){
			return;
		}
		if(code==""){
			return;
		}
		$.post("../adminInfoServlet",{op:"adminLogin",role:role,name:name,pwd:pwd,code:code},function(data){
		
			data=parseInt($.trim(data));
				
				if(data==1){
					$("#vcode").css("border-color","red");
				}else if(data==2){
					alert("用户名或者密码错误");
				}else if(data==3 ){
					var r=parseInt($.trim(role));
					if(r==1001){
						location.href="manager/index.html";
					}else{
						location.href="manager02/index.html";
					}
					
				}else{
					alert("用户名或者密码错误");
				}
			
		});
	}
	
	//注册
	function register(){
		var role=$.trim($("#rodeId").val());//角色id
		var rname=$.trim($("#rname").val());//用户名
		var rpwd=$.trim($("#rpwd").val());//密码
		var rpwds=$.trim($("#rpwds").val());//密码
		var email=$.trim($("#email").val());//邮箱
		var tel=$.trim($("#tel").val());//电话
		
		alert(rname+"\t"+rpwd+"\t"+rpwds+"\t"+email+"\t"+tel);
		if(rpwds!=rpwd){
			$("#rpwds").css("border-color","red");//如果两次密码不一致，则重新输入密码框变成红色方便提示用户
		}
		if(role==null || role==""){
			return;
		}
		if(rname==null || rname==""){
			return;
		}
		if(rpwd==null || rpwd==""){
			return;
		}
		if(rpwds==null || rpwds==""){
			return;
		}
		if(email==null || email==""){
			return;
		}
		if(tel==null || tel==""){
			return;
		}
		$.post("../adminInfoServlet",{op:"register_admin",role:role,rname:rname,rpwd:rpwd,email:email,tel:tel},function(data){
			alert(data);
		});
	}
	
</script>
</head>

<body>
	
	<div class="container">
		<div class="row">
        	<div class="col-md-4">
            	<br/><br/>
            	 <img src="../img/logo.png" width="100%"/>
            </div>
            
            <div class="col-md-5 col-md-offset-1">
            	<div class="panel">
                	<div class="panel-heading login-top">用户登录</div>
                    <div class="panel-body">
                    	<form class="form-group col-lg-10 col-md-offset-1" action="" method="post" role="form"">
                    		<input type="hidden" id="rodeId"/>
                			<div class="input-group">
								<div class="input-group-btn">
									<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">角&nbsp;&nbsp;色<span class="caret"></span></button>
									<ul class="dropdown-menu" id="loginRoles">
										
									</ul>
								</div>
								<input id="loginrole" type="text" class="form-control" disabled="disabled" required placeholder="请选择角色"/>	
								<label class="input-group-addon"><a href="callbackpassword.html" class="errorinfo">忘记密码...</a></label>
							</div>
                            <br />
                            <div class="input-group">
                            	<label for="uname" class="input-group-addon">用户名</label>
                                <input type="text" class="form-control" name="uname" id="uname" required placeholder="请输入用户编号或邮箱"/>
                            </div>
                            <br />
                            <div class="input-group">
                            	<label for="pwd" class="input-group-addon">密&nbsp;&nbsp;&nbsp;码</label>
                                <input type="password" class="form-control" name="pwd" id="pwd" required  placeholder="请输入密码"/>
                            </div>
                            <br />
                            <div class="input-group">
                            	<label for="vcode" class="input-group-addon">验证码</label>
                                <input type="text" class="form-control" name="vcode" id="vcode" required placeholder="请输入右边的验证码"/>
                                <label class="input-group-btn"><img src="valiCodeImg.jsp" onclick="this.src='valiCodeImg.jsp?d='+new Date()"/></label>
                            </div>
                            <br/>
                            <div class="input-group">
                            	<input type="button" value="登陆" class="btn btn-success mybtn" onclick="adminLogin()"/>
                                <input type="reset" value="重置" class="btn btn-warning mybtn"/>
                            </div>
                            <br/>
                            <div class="input-group">
                            	<input type="button" value="注册" onClick="showRegisterPage()" class="btn btn-danger user-register" />
                            </div>
                		</form>
                    </div>
                    <div class="panel-footer login-footer">DMS &copy; 版权所有</div>
                </div>
            </div>
            <div class="col-md-2"></div>
        </div>
	</div>
    
    <div class="register-page">
		<div class="close-button">X</div>
        <div class="register col-lg-6">
            <div class="panel">
                <div class="panel-heading login-top">用户注册</div>
                <div class="panel-body">
                    <form class="form-group col-lg-12" action="" method="post" role="form">
                        <div class="input-group">
                            <div class="input-group-btn">
                                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">角&nbsp;&nbsp;色<span class="caret"></span></button>
                                <ul class="dropdown-menu" id="registerRoles">
                                    <!-- <li><a id="role1" href="javascript:login('role1','role')">学工处</a></li>
                                    <li><a id="role2" href="javascript:login('role2','role')">保卫处</a></li>
                                    <li><a id="role3" href="javascript:login('role3','role')">书记</a></li>
                                    <li><a id="role4" href="javascript:login('role4','role')">辅导员</a></li>
                                    <li><a id="role5" href="javascript:login('role5','role')">超级管理员</a></li> -->
                                </ul>
                            </div>
                            <input id="role" type="text" class="form-control" disabled="disabled" required placeholder="请选择角色"/>							<label class="input-group-addon"><a href="javascript:backlogin()" class="errorinfo">我已有账号...</a></label>
                        </div>
                        <br />
                        <div class="input-group">
                            <label for="rname" class="input-group-addon">用户名</label>
                            <input type="text" class="form-control" name="uname" id="rname" required placeholder="请输入用户名" maxlength="12"/ >								<label class="input-group-addon promptinfo">由2-12位的中文、字母、数字和下划线组成</label>
                        </div>
                        <br />
                        <div class="input-group">
                            <label for="rpwd" class="input-group-addon">密&nbsp;&nbsp;&nbsp;码</label>
                            <input type="password" class="form-control" name="rpwd" id="rpwd" required  placeholder="请输入密码" maxlength="16"/>
                            <label class="input-group-addon promptinfo">由6-16位的字母、数字和下划线组成</label>
                        </div>
                        <br />
                        <div class="input-group">
                            <label for="rpwds" class="input-group-addon">确认密码</label>
                            <input type="password" class="form-control" name="rpwds" id="rpwds" required placeholder="请再输入一次密码，以确认" maxlength="16"/>
                            <label class="input-group-addon promptinfo">请再输入一次密码，以确认</label>
                        </div>
                        <br/>
                        <div class="input-group">
                            <label for="email" class="input-group-addon">邮&nbsp;&nbsp;&nbsp;箱</label>
                            <input type="email" class="form-control" name="email" id="email" required placeholder="请输入您的邮箱账号"/>
                            <label class="input-group-addon promptinfo">请输入邮箱账号，以便忘记密码时找回</label>
                        </div>
                        <br/>
                        <div class="input-group">
                            <label for="tel" class="input-group-addon">联系方式</label>
                            <input type="number" class="form-control" name="tel" id="tel" maxlength="12" required placeholder="请输入您联系方式"/>
                            <label class="input-group-addon promptinfo">请输您的联系方式</label>
                        </div>
                        <br/>
                        <div class="input-group">
                            <input type="button" value="注册" class="btn btn-success user-register" onclick="register()"/>
                            <input type="reset" value="重置" class="btn btn-danger mybtn"/>
                        </div>
                     </form>
                </div>
                <div class="panel-footer login-footer">DMS &copy; 版权所有</div>
            </div>
        </div>
	</div>
</body>
</html>
